class Solution
{
public:
    void sortColors(vector<int>& nums)
    {
        int a = 0, b = nums.size();
        for (int i = 0; i < b; ++i)
        {
            if (nums[i] == 0)
                swap(nums[i], nums[a++]);
            else if (nums[i] == 2)
                swap(nums[i--], nums[--b]);
        }
    }
};